<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <script>
        const A = new Set([1, 2, 3, 4, 5]);
        const B = new Set([4, 5, 6, 7, 8]);

        // 求交集
        const intersection = [...A].filter(element => B.has(element));

        // 求并集A
        const union = [...A, ...B];

        // 求差集
        const differenceAB = [...A].filter(element => !B.has(element));

        console.log(`交集= (${intersection.length}) ${intersection}`);
        console.log(`并集= (${union.length}) ${union}`);
        console.log(`差集= (${differenceAB.length}) ${differenceAB}`);
    </script>
</head>
<body></body>

</html>